package cn.szzsi.business.controller.web;

import cn.szzsi.model.Question;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;

import java.util.Date;
import java.util.List;

public class QuestionController extends Controller {
    public void index(){
        render("question.html");
    }

    public void list(){
        String wang=getSessionAttr("wang");
        if(wang==null){
            redirect("/active/questionnaire/login");
        }else{
            List<Question> questionList=Question.dao.find("select * from sys_question order by hasRead asc,createDate desc");
            setAttr("questionList",questionList);
            render("question_list.html");
        }

    }

    public void detail(){
        String id=getPara("id");
        Question question=Question.dao.findById(id);
        if(question!=null){
            question.setHasRead("1");
            question.update();
            setAttr("question",question);
            render("question_view.html");
        }else{
            renderJson(Ret.fail());
        }

    }

    public void save(){
        Question question=getModel(Question.class);
        question.setCreateDate(new Date());
        question.save();
        renderJson(Ret.ok());
    }


    public void login(){
        render("login.html");
    }
    public void toLogin(){
        String password=getPara("password");
        if(!"wtong".equals(password)){
            renderJson(Ret.fail("info","哼,你不是彤,不理你!"));
            return;
        }
        setSessionAttr("wang","wang");
        renderJson(Ret.ok("info","希望你每天都有一个好心情哦!"));


    }
}
